IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'spUsers_RetrieveAll')
	BEGIN
		PRINT 'Dropping Procedure spUsers_RetrieveAll'
		DROP  Procedure  spUsers_RetrieveAll
	END

GO

PRINT 'Creating Procedure spUsers_RetrieveAll'
GO

CREATE Procedure spUsers_RetrieveAll
	(
		@User_ID numeric(9,0) = null, 
		@UserLogon varchar(50) = null, 
		@UserPassword varchar(50) = null, 
		@FirstName varchar(100) = null, 
		@Surname varchar(100) = null, 
		@Extention varchar(50) = null, 
		@Telephone varchar(50) = null, 
		@Cellphone varchar(50) = null, 
		@Email varchar(250) = null, 
		@DivisionName varchar(50) = null, 
		@DepartmentName varchar(50) = null, 
		@Access varchar(5000) = null, 
		@Active numeric = null
	)
AS
    /* 
    ------------------------------------------------------------------------------
    - Change History
    - --------------
    - Date          Description
    ------------------------------------------------------------------------------
    - 2007/11/02	Initial version created
    ------------------------------------------------------------------------------
    */
	
	SET NOCOUNT ON
	
	-- Retrieve the relevant records
	SELECT  *
	FROM	Users
	
	WHERE	(@User_ID IS NULL OR Users.User_ID = @User_ID)
	  AND	(@UserLogon IS NULL OR Users.UserLogon LIKE @UserLogon + '%')
	  AND	(@UserPassword IS NULL OR Users.UserPassword LIKE @UserPassword + '%')
	  AND	(@FirstName IS NULL OR Users.FirstName LIKE @FirstName + '%')
	  AND	(@Surname IS NULL OR Users.Surname LIKE @Surname + '%')
	  AND	(@Extention IS NULL OR Users.Extention LIKE @Extention + '%')
	  AND	(@Telephone IS NULL OR Users.Telephone LIKE @Telephone + '%')
	  AND	(@Cellphone IS NULL OR Users.Cellphone LIKE @Cellphone + '%')
	  AND	(@Email IS NULL OR Users.Email LIKE @Email + '%')
	  AND	(@DivisionName IS NULL OR Users.DivisionName LIKE @DivisionName + '%')
	  AND	(@DepartmentName IS NULL OR Users.DepartmentName LIKE @DepartmentName + '%')
	  AND	(@Access IS NULL OR Users.Access LIKE @Access + '%')
	  AND	(@Active IS NULL OR Users.Active = @Active)

	-- Return to calling method
	RETURN
GO
